function flatten(arr) {
  let result = [...arr];

  while (result.some((item) => Array.isArray(item))) {
    result = [].concat(...result);

    console.log(result);
  }
  return result;
}

//[1, 2, [3, 4, [5]],[6]]
//[1, 2, 3, 4, [5]],6]
//[1, 2, 3, 4, [5],6]
